package tree;


/**
 * This class provides all types
 */
public class Type {
	
	private DataType t;
	private String classOrGenericName;
	private Type arrayType = null;
	
	public Type(DataType t, String classOrGenericName) {
		this.t = t;
		this.classOrGenericName = classOrGenericName;
	}
	
	public Type(DataType t, Type arrayType) {
		this.t = t;
		this.arrayType = arrayType;
		this.classOrGenericName = "";
	}
	
	public Type getArrayOrGenericType() {
		return this.arrayType;
	}
	
	public DataType getDataType() {
		return this.t;
	}
	
	public String getClassOrGenericName() {
		return this.classOrGenericName;
	}

	@Override
	public boolean equals(Object obj) {
		if (obj instanceof Type) {
			Type typ = (Type) obj;
			if (this.getDataType().equals(typ.getDataType())) {
				if (typ.getDataType().equals(DataType.REF)) {
					return (this.getClassOrGenericName().equals(typ.getClassOrGenericName()));
				}
				else if ((typ.getDataType().equals(DataType.ARR)) ||
						(typ.getDataType().equals(DataType.GEN))) {
					return this.getArrayOrGenericType().equals(typ.getArrayOrGenericType());
				}
				return true;
			}
			return false;			
		}
		else {
			return false;
		}

	}
}